<template>
  <div class="">
    <div class="page-filter mb10 fl">
      <el-form ref="filter" :model="filter" label-width="0">
        <el-form-item class="mr10 mb5 fl">
          <el-input v-model="filter.nickname" placeholder="姓名" size="small" clearable />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl">
          <el-date-picker
              v-model="filter.date"
              type="month"
              format="yyyy-MM"
              value-format="yyyy-MM"
              size="small"
              clearable
              style="width: 100%"
            />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" style="width: 300px">
          <el-button size="small" @click="app.reset('filter')">清 空</el-button>
          <el-button type="primary" size="small" @click="getList">查 询</el-button>
          <el-button type="primary" size="small" @click="handleOutAttendances">导出打卡记录</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="app.loading" class="search-table" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="序号" align="center" width="56px">
        <template slot-scope="{$index}">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="120px" prop="nickname" />
      <el-table-column label="部门" width="120px" prop="dept_name" />
      <el-table-column label="职务" width="120px" prop="pos_name" />
      <el-table-column label="类型" align="center" width="80px" :formatter="formatterType" />
      <el-table-column label="日期" align="center" width="110px" prop="punch_time" />
      <el-table-column label="打卡时间" align="center" width="140px" prop="create_time" />
      <el-table-column label="打卡地点" width="260px" prop="place" />
      <el-table-column label="范围内" align="center" width="80px" :formatter="formatterRange" />
      <el-table-column label="备注" min-width="260px" prop="remark" />
      <el-table-column label="打卡地点" align="center" width="90px" fixed="right">
        <template slot-scope="{row}">
          <el-button @click.native="handleShow(row)" type="primary" size="mini">
            地 点
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
    <Map ref="map" :get-data="getList" :info="dialog" />
  </div>
</template>

<script>
import { works } from '@/api/punch'
import { outAttendances } from '@/api/finance/salary'
import Map from './components/work-map'
import page from '@/utils/page'

export default {
  name: '',
  components: { Map },
  extends: page,
  props: {
    reqList: {
      default: works,
      type: Function
    }
  },
  data() {
    return {
      
    }
  },
  created() {
    this.$set(this.filter, 'date', new Date())
    this.getList()
  },
  methods: {
    handleShow(e) {
      this.dialog.title = '打卡地点'
      this.dialog.type = 'edit'
      this.app.dialogParam(this.dialog.edit, ['longitude', 'latitude'], e)
      this.$refs['map'].visible = true
    },
    handleOutAttendances() {
      outAttendances({
        ...this.filter
      }).then(response => {
        this.out(response)
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    formatterRange(e) {
      let o = e.range
      if(o === 0) {
        return '否'
      }else{
        return '是'
      }
    },
    formatterType(e) {
      let type = e.type
      if(type === 1){
        return '上班'
      } else {
        return '下班'
      }
    }
  }
}
</script>
